package com.amit.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class Log4Util  implements ServletContextListener{
	
	Logger log=Logger.getLogger(Log4Util.class);


	@Override
	public void contextInitialized(ServletContextEvent sce) {
		
		ServletContext ctx=sce.getServletContext();
		String path=ctx.getRealPath("/");
		path=path+"/logs";
		System.setProperty("log.file.location", path);
		String logfile=ctx.getRealPath("/WEB-INF/classes/log4j.properties");
		System.out.println(logfile);
		PropertyConfigurator.configure(logfile);
		log.info("Log4j System is initialized at container startup");
	}
	
	
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		
		
	}


}
